<?php
class Application_Model_CalPort
{
	protected $_dbTable;
	public $_mId;
	public $_mDate;
	public $_mDmLargeMc;
	public $_mDmMidMc;
	public $_mDmSmallMc;
	public $_mDmLargeMcRet;
	public $_mDmMidMcRet;
	public $_mDmSmallMcRet;
	public $_mDmIndex;
	public $_mDmIndexRet;

	public function getId(){
		return $this->_mId;
	}
	public function setId($value){
		$this->_mId = $value;
		return $this;
	}
	public function getDate(){
		return $this->_mDate;
	}
	public function setDate($value){
		$this->_mDate = $value;
		return $this;
	}
	public function getDmLargeMc(){
		return $this->_mDmLargeMc;
	}
	public function setDmLargeMc($value){
		$this->_mDmLargeMc = $value;
		return $this;
	}
	public function getDmMidMc(){
		return $this->_mDmMidMc;
	}
	public function setDmMidMc($value){
		$this->_mDmMidMc = $value;
		return $this;
	}
	public function getDmSmallMc(){
		return $this->_mDmSmallMc;
	}
	public function setDmSmallMc($value){
		$this->_mDmSmallMc = $value;
		return $this;
	}
	public function getDmLargeMcRet(){
		return $this->_mDmLargeMcRet;
	}
	public function setDmLargeMcRet($value){
		$this->_mDmLargeMcRet = $value;
		return $this;
	}
	public function getDmMidMcRet(){
		return $this->_mDmMidMcRet;
	}
	public function setDmMidMcRet($value){
		$this->_mDmMidMcRet = $value;
		return $this;
	}
	public function getDmSmallMcRet(){
		return $this->_mDmSmallMcRet;
	}
	public function setDmSmallMcRet($value){
		$this->_mDmSmallMcRet = $value;
		return $this;
	}
	public function getDmIndex(){
		return $this->_mDmIndex;
	}
	public function setDmIndex($value){
		$this->_mDmIndex = $value;
		return $this;
	}
	public function getDmIndexRet(){
		return $this->_mDmIndexRet;
	}
	public function setDmIndexRet($value){
		$this->_mDmIndexRet = $value;
		return $this;
	}


	public function setDbTable($dbTable){
		if (is_string($dbTable))
			$dbTable = new $dbTable();
		if (!$dbTable instanceof Zend_Db_Table_Abstract)
			throw new Exception('Invalid table data gateway provided');
		$this->_dbTable = $dbTable;
        
		return $this;
	}
	public function getDbTable(){
		if (null === $this->_dbTable)
			$this->setDbTable('Application_Model_DbTable_CalPort');
		return $this->_dbTable;
	}
	public function save(Application_Model_CalPort $old = null){
		$item = $this;
		$data = array();
		if(isset($item->_mId)) $data['id'] = $item->_mId;
		if(isset($item->_mDate)) $data['date'] = $item->_mDate;
		if(isset($item->_mDmLargeMc)) $data['dm_large_mc'] = $item->_mDmLargeMc;
		if(isset($item->_mDmMidMc)) $data['dm_mid_mc'] = $item->_mDmMidMc;
		if(isset($item->_mDmSmallMc)) $data['dm_small_mc'] = $item->_mDmSmallMc;
		if(isset($item->_mDmLargeMcRet)) $data['dm_large_mc_ret'] = $item->_mDmLargeMcRet;
		if(isset($item->_mDmMidMcRet)) $data['dm_mid_mc_ret'] = $item->_mDmMidMcRet;
		if(isset($item->_mDmSmallMcRet)) $data['dm_small_mc_ret'] = $item->_mDmSmallMcRet;
		if(isset($item->_mDmIndex)) $data['dm_index'] = $item->_mDmIndex;
		if(isset($item->_mDmIndexRet)) $data['dm_index_ret'] = $item->_mDmIndexRet;

		if($old === null)
			$this->getDbTable()->insert($data);
		else{
			$key = array();
			$old->_mId === null ? $key[] = 'id is NULL' : $key['id = ?'] =  $old->_mId;

			$this->getDbTable()->update($data, $key);
		}
	}
	public function delete(){
		$item = $this;
		$old = $item;
		$key = array();
			$old->_mId === null ? $key[] = 'id is NULL' : $key['id = ?'] =  $old->_mId;

		$this->getDbTable()->delete($key);
	}
	public function fetchAll($where = null, $order = null, $count = null, $offset = null){
		$resultSet = $this->getDbTable()->fetchAll($where, $order, $count, $offset);
		$entries   = array();
		foreach ($resultSet as $row) {
			$item = new Application_Model_CalPort();
			if(isset($row->id))$item->_mId = $row->id;
			if(isset($row->date))$item->_mDate = $row->date;
			if(isset($row->dm_large_mc))$item->_mDmLargeMc = $row->dm_large_mc;
			if(isset($row->dm_mid_mc))$item->_mDmMidMc = $row->dm_mid_mc;
			if(isset($row->dm_small_mc))$item->_mDmSmallMc = $row->dm_small_mc;
			if(isset($row->dm_large_mc_ret))$item->_mDmLargeMcRet = $row->dm_large_mc_ret;
			if(isset($row->dm_mid_mc_ret))$item->_mDmMidMcRet = $row->dm_mid_mc_ret;
			if(isset($row->dm_small_mc_ret))$item->_mDmSmallMcRet = $row->dm_small_mc_ret;
			if(isset($row->dm_index))$item->_mDmIndex = $row->dm_index;
			if(isset($row->dm_index_ret))$item->_mDmIndexRet = $row->dm_index_ret;

			$entries[] = $item;
		}
		return $entries;
	}
}
